package com.zl.easybuy.service.impl;

import com.zl.easybuy.exception.EasyBuyException;
import com.zl.easybuy.mapper.UserAddressMapper;
import com.zl.easybuy.pojo.User;
import com.zl.easybuy.pojo.UserAddress;
import com.zl.easybuy.service.UserAddressService;
import com.zl.easybuy.util.SessionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserAddressServiceImpl implements UserAddressService{
    @Autowired
    private UserAddressMapper userAddressMapper;

    @Override
    public List<UserAddress> queryAddressByUserId()throws EasyBuyException{
        //获取session中的用户信息
        User currentUser = SessionUtils.getCurrentUser();
        if(currentUser != null){ //用户存在
            List<UserAddress> userAddressesList =  userAddressMapper.queryByUserId(currentUser.getId());
            return userAddressesList;
        }
        //如果session中没有用户信息, 抛一个异常, 让用户去登录
        throw new EasyBuyException("未登录,请重新登录");
    }
}
